import axios from 'axios';
import {router} from "../router";

axios.defaults.timeout = 5000;
axios.defaults.withCredentials = true; //让ajax携带cookie
//axios.defaults.baseURL = 'http://localhost:8080/background';


axios.interceptors.response.use(
  response => {
    return response;
  },
  error => {
    if (error.response) {
      switch (error.response.status) {
        case 401:
          router.replace({
            name: 'Login',
            query: {redirect: router.currentRoute.fullPath}
          })
      }
    }
    return Promise.reject(error.response.data)   // 返回接口返回的错误信息
  });

export default axios
